package com.wedo.mall.activity.user;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.e.library.utils.EViewUtils;
import com.wedo.mall.R;
import com.wedo.mall.adapter.GoodsRecordAdapter;
import com.wedo.mall.entity.Goods;
import com.wedo.mall.entity.GoodsRecord;
import com.wedo.mall.entity.GoodsRecordItem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import io.reactivex.Observable;

public class PurchaseRecordActivity extends EActivity {

    @BindView(R.id.rv_purchaserecord) RecyclerView rv_purchaserecord;
    private GoodsRecordAdapter goodsRecordAdapter;

    @Override
    protected int layout() {
        return R.layout.activity_purchase_record;
    }

    @Override
    protected void onActivityCreated(Bundle state) {
        rv_purchaserecord.setHasFixedSize(true);
        EViewUtils.vertical(rv_purchaserecord);
        goodsRecordAdapter = new GoodsRecordAdapter(this,new ArrayList<GoodsRecord>());
        rv_purchaserecord.setAdapter(goodsRecordAdapter);


    }

    @Override
    protected void onResume() {
        super.onResume();
        purchaseHistory();
    }

    /**推荐商品*/
    private void purchaseHistory(){
        this.loading();
        Map<String,String> params = new HashMap<>(1);
        params.put("page","1");
        Observable<EResponse> observable = EClient.with().api().post(EApi.USER_HISTORY,params);
        EClient.with().observer(observable, new EObserver() {
            @Override
            public void successful(EResponse response) {
                List<GoodsRecord> list = response.list(GoodsRecord.class);
                goodsRecordAdapter.refresh(list);
                PurchaseRecordActivity.this.dismiss();
            }

            @Override
            public void failure(String msg) {
                PurchaseRecordActivity.this.dismiss(msg);
            }

        });
    }

}
